import Immutable from 'immutable';

const defaultState = new Immutable.List();

export default function SysUserReducer(state = defaultState, action) {
  switch(action.type) {
    case 'CREATE_SYSUSER_DATA':
      var data = action.data;
      if (data.success) {
          return state.concat(data.data);
      }else {
        return [];
      }
    case 'EDIT_SYSUSER_DATA':
      var data = action.data
      console.log(data);
      return state;
    case 'DELETE_SYSUSER_DATA':
      console.log(action.id);
      state = _.remove(state, function(SysUser) {
        console.log(SysUser.id, action.id)
        return action.id !== SysUser.id
      })
      return state;
    case 'LOAD_SYSUSER_DATA':
      var data = action.data;
      if (data.success) {
        return data;
      }else {
        return [];
      }
    default:
      return state;
  }
}
